package cn.arikeky.interceptors;

import cn.arikeky.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 拦截器类
 */
public class UserInterceptor implements HandlerInterceptor {
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//
//        System.out.println("经过了拦截器");
////        response.setHeader("Access-Control-Allow-Origin",request.getHeader("Origin"));//支持跨域请求
////        response.setHeader("Access-Control-Allow-Methods", "*");
////        response.setHeader("Access-Control-Allow-Credentials", "true");//是否支持cookie跨域
////        response.setHeader("Access-Control-Allow-Headers", "Authorization,Origin, X-Requested-With, Content-Type, Accept,Access-Token");//Origin, X-Requested-With, Content-Type, Accept,Access-Token
//
//        // 从session中获取user的信息
//        try {
//
//
//        User user = (User) request.getSession().getAttribute("user");
//        // 判断用户是否登录
//        if (user != null){
//            return true;
//        }
//            response.sendRedirect(request.getContextPath()+"http://localhost:8081/#/");
//        } catch (IOException e){
//            e.printStackTrace();
//        }
//        return false;
//    }
}
